package ar.uba.dc.webming.tp1.output;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigDecimal;

import ar.uba.dc.webming.tp1.measures.ResultSetEvaluator;






public class QueryResultFileWriter {
    private FileWriter writer;
    
    public QueryResultFileWriter(File aFile) throws IOException{
        writer = new FileWriter(aFile);
        writer.append("QUERY-NUM"
                +"\tTOTAL-RETRIEVED "
                +"\tRELEVANT-ITEMS "
                +"\tPRECISION " 
                +"\tRECALL " 
                +"\tR-PRECISION "
                +"\n");
    }
    
    public void appendResults(ResultSetEvaluator evaluator) throws IOException{
    	///new BigDecimal();
    	//BigDecimal.valueOf(evaluator.calculatePrecision());
        writer.append(evaluator.getQueryNum()
                +"\t"+evaluator.totalResults()
                //+"\trelevant-items-retrieved: "+evaluator.relItemsRetrieved()
                +"\t"+evaluator.relevantItems()
                +"\t" + BigDecimal.valueOf(evaluator.calculatePrecision())
                +"\t"+ BigDecimal.valueOf(evaluator.calculateRecall()) 
                +"\t" + BigDecimal.valueOf(evaluator.calculateRPrecision()) 
                +"\n");
    }

    public void close() throws IOException{
        writer.close();
    }
}
